import * as types from './mutations_types';
import {
    questionnaire
} from '../../api/education';
import {
    savaToLocal
} from '../../common/js/store';
module.exports = {
    login_user: ({
        dispatch,
        commit
    }, {
        self,
        obj
    }) => {
        return new Promise((resolve, reject) => {
            questionnaire.getLoginAndNameAction.call(self, obj, data => {
                savaToLocal('user', 'userinfo', data);
                resolve();
            }, () => {
                reject();
            });
        });
    },
    // validateization: ({
    //     dispatch,
    //     commit
    // }, {
    //     self,
    //     obj
    // }) => {
    //     return new Promise((resolve, reject) => {
    //         questionnaire.validateAuthorization.call(self, obj, data => {
    //             savaToLocal('user', 'userinfo', data);
    //             dispatch('update_user');
    //             resolve();
    //         }, () => {
    //             reject();
    //         });
    //     });
    // },
    quest_list: ({
        commit
    }, {
        self,
        query
    }) => {
        return new Promise((resolve, reject) => {
            questionnaire.questionnaireListAction.call(self, query, data => {
                console.log(data);
                commit(types.QUEST_LIST, data);
                resolve();
            }, () => {
                reject();
            });
        });
    },
    checkScores: ({
        commit
    }, {
        self,
        query
    }) => {
        return new Promise((resolve, reject) => {
            questionnaire.checkScores.call(self, query, data => {
                commit(types.CHECK, data);
                resolve();
            }, () => {
                reject();
            });
        });
    },
    questionList: ({
        commit
    }, {
        self,
        query
    }) => {
        return new Promise((resolve, reject) => {
            questionnaire.queryQuestionList.call(self, query, data => {
                commit(types.QUESTION_LIST, data);
                resolve();
            }, () => {
                reject();
            });
        });
    },
    deleteQuest: ({
        commit
    }, {
        self
    }) => {
        return new Promise((resolve, reject) => {
            questionnaire.deleteAQuestionnarieAction.call(self, {}, data => {
                console.log(data);
                commit(types.DELETE_QUEST, data);
                resolve();
            }, () => {
                reject();
            });
        });
    }
};